package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author: xuesm
 * @date: 2025/2/19 21:37
 */
@RestController
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMsg")
    public String sendMsg(@RequestParam(value = "num", defaultValue = "10") Integer num){
        for (int i = 0; i < num; i++) {
            if (i%2==0){
                OrderEntity entity = new OrderEntity();
                entity.setId(1l);
                entity.setMemberUsername("哈哈哈-"+i);
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", entity, new CorrelationData(UUID.randomUUID().toString()));
                System.out.println("消息发送成功...");
            }else {
                OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
                entity.setId(1L);
                entity.setName("哦哦哦-"+i);
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello22.java", entity, new CorrelationData(UUID.randomUUID().toString()));
                System.out.println("消息发送成功...");
            }
        }

        return "ok";
    }
}
